package com.qiaoba.common.base.util;

import java.lang.reflect.Field;

/**
 * 对象工具类
 *
 * @author ailanyin
 * @date 2023-09-16 11:12:20
 */
public class ObjectUtil {

    public static boolean allFieldsIsEmpty(Object obj) {
        // 如果对象为null，视为所有字段都为空
        if (obj == null) {
            return true;
        }

        Class<?> clazz = obj.getClass();
        Field[] fields = clazz.getDeclaredFields();

        for (Field field : fields) {
            try {
                field.setAccessible(true);
                Object value = field.get(obj);
                if (value != null) {
                    if (field.getType() == String.class) {
                        if (!((String) value).isEmpty()) {
                            return false;
                        }
                    } else {
                        return false;
                    }
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }

        return true;
    }
}
